# sudo add-apt-repository universe;

sudo apt-get update;

sudo apt-get upgrade -y;

sudo adduser --system --quiet --shell=/bin/bash --home=/home/odoo --gecos 'ODOO' --group odoo;

sudo apt-get install postgresql -y;

sudo su - postgres -c "createuser -s odoo" 2> /dev/null || true;

#sudo wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.5/wkhtmltox_0.12.5-1.bionic_amd64.deb;


echo -e "\n--- Installing Python 3 + pip3 --"
sudo apt-get install python3 python3-pip python3-polib -y;
sudo apt-get install python-dev python3-wheel gdebi -y;
sudo apt-get install python3-babel python3-dateutil python3-decorator python3-docutils python3-feedparser python3-gevent python3-html2text -y;
sudo apt-get install python3-jinja2 python3-libsass python3-lxml python3-mako -y;
sudo apt-get install python3-mock python3-ofxparse python3-passlib python3-psutil python3-psycopg2 -y;
sudo apt-get install python3-pydot python3-pyparsing python3-pypdf2 python3-reportlab -y;
sudo apt-get install python3-qrcode python3-vobject  python3-zeep  python3-pyldap -y;
sudo apt-get install python3-qrcode -y;
sudo apt-get install python3-vobject -y;
sudo apt-get install python3-zeep -y;
sudo apt-get install python3-pyldap -y;
sudo apt-get install python3-serial python3-usb python3-vatnumber python3-werkzeug python3-xlsxwriter python3-suds python3-xlrd -y;
sudo apt-get install libldap2-dev libsasl2-dev -y;
# nginx 源码安装的支持
sudo apt-get install libpcre3 libpcre3-dev -y;
sudo apt-get install zlib1g-dev -y;
sudo apt-get install openssl -y;
sudo apt-get install libssl-dev -y;
sudo apt-get install phthon3-phonenumbers -y;

echo -e "\n---- Install tool packages ----"
# 要单独执行，因为 u16和u18有些包不同，放一个语句容易出错
sudo apt-get install sntp -y;
sudo apt-get install git -y;
sudo apt-get install bzr -y;
sudo apt-get install gdebi-core -y;
sudo apt-get install xfonts-base xfonts-75dpi -y;

echo -e "\n--- Install other required packages"
sudo apt-get install node-clean-css -y;
sudo apt-get install node-less -y;
sudo apt-get install python-gevent -y;
sudo apt-get install libxml2-dev libxslt1-dev libevent-dev libsasl2-dev libldap2-dev libpq-dev libpng-dev libjpeg-dev xz-utils -y;
# 中文字体
sudo apt-get install xfonts-utils -y;
sudo apt-get install unzip -y;
sudo apt-get install ttf-wqy-* -y && sudo apt-get install ttf-wqy-zenhei -y && sudo apt-get install ttf-wqy-microhei -y;
sudo apt-get install language-pack-zh-hant language-pack-zh-hans -y;

sudo dpkg -i wkhtmltox_0.12.5-1.trusty_amd64.deb -y;

sudo apt-get install -f;

sudo ln -s /usr/local/bin/wkhtmltopdf /usr/bin;

sudo ln -s /usr/local/bin/wkhtmltoimage /usr/bin;

sudo pip3 install phonenumbers num2words scss libsass polib -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install python-Levenshtein -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install python-barcode -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install vobject qrcode pycrypto -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install xlwt xlsxwriter xlrd -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install pyldap -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install firebase_admin -i https://pypi.tuna.tsinghua.edu.cn/simple;
# 中文分词
sudo pip3 install jieba -i https://pypi.tuna.tsinghua.edu.cn/simple;
# odoo13 企业版
sudo pip3 install zeep -i https://pypi.tuna.tsinghua.edu.cn/simple;
# 微信与阿里
sudo pip3 install wechatpy python-alipay-sdk pycryptodome -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install itsdangerous==0.24 -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install kdniao==0.1.2 -i https://pypi.tuna.tsinghua.edu.cn/simple;
sudo pip3 install xmltodict==0.11.0 -i https://pypi.tuna.tsinghua.edu.cn/simple;

# 本地化
sudo apt-get install aptitude -y;sudo aptitude install -y locales;
# 设置时区，默认先不设置，因为有时是境外主机
# sudo timedatectl set-timezone "Asia/Shanghai"
# sudo timedatectl set-timezone "America/New_York"
# 将你的硬件时钟设置为协调世界时（UTC）：
sudo timedatectl set-local-rtc 0;
# 自动时间同步到远程NTP服务器，须卸载ntp
sudo apt-get remove ntp -y;
sudo timedatectl set-ntp no;
sudo apt-get install ntpdate -y;
# 设置系统时间与网络时间同步
ntpdate cn.pool.ntp.org;
# 将系统时间写入硬件时间
sudo hwclock --systohc;
sudo apt-get install node-clean-css -y;

sudo apt-get install node-less -y;

sudo apt-get install python-gevent -y;

sudo mkdir /odoo;

sudo mkdir /odoo/odoofile;

sudo mkdir /odoo/logs;

sudo mkdir /odoo/myaddons

#sudo chown odoo:odoo /var/log/odoo;

#sudo apt-get install git;

sudo git clone --depth 1 --branch 13.0 https://gitee.com/mirrors/odoo.git /odoo/odoo-server;
#

sudo cp odoo-bin /odoo;

# sudo wget https://nightly.odoocdn.com/13.0/nightly/src/odoo_13.0.latest.tar.gz;

# tar -xzvf odoo_13.0.latest.tar.gz /odoo/odoo-server;

sudo chown -R odoo:odoo /odoo/*;

sudo touch /odoo/odoo-server.conf;

sudo su root -c "printf '[options] \n; This is the password that allows database operations:\n' >> /odoo/odoo-server.conf";

sudo su root -c "printf 'admin_passwd = admin\n' >> /odoo/odoo-server.conf";

sudo su root -c "printf 'xmlrpc_port = 8069\n' >> /odoo/odoo-server.conf";

sudo su root -c "printf 'data_dir = /odoo/odoofile\n' >> /odoo/odoo-server.conf";

sudo su root -c "printf 'logfile = /odoo/logs/odoo-server.log\n' >> /odoo/odoo-server.conf";

sudo su root -c "printf 'addons_path=/odoo/odoo-server/addons,/odoo/myaddons\n' >> /odoo/odoo-server.conf";

sudo chown odoo:odoo /odoo/odoo-server.conf;

sudo chmod 640 /odoo/odoo-server.conf;

sudo chmod -x /odoo/odoo-bin

sudo su - odoo -c "cd /odoo; ./odoo-bin -c /odoo/odoo-server.conf &"